package com.yyds.controller;

import com.yyds.common.MyJSON;
import com.yyds.common.R;
import com.yyds.pojo.PreventRegion;
import com.yyds.service.PreventRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/prevent/region")
public class PreventRegionController {
    @Autowired
    private PreventRegionService preventRegionService;

    //查全部封控地区
    @RequestMapping("/list")
    public MyJSON<PreventRegion> list(PreventRegion preventRegion, int page, int limit){
        return preventRegionService.selectAllPreventRegionService(preventRegion,page, limit);
    }
    //添加
    @RequestMapping("/add")
    public R add(PreventRegion preventRegion){
        return preventRegionService.insertPreventRegionService(preventRegion);
    }
    //删除
    @RequestMapping("/delete")
    public R delete(Integer region_id){
        int result = preventRegionService.deletePreventRegionServiceById(region_id);
        System.out.println(region_id);

        if (result ==1){
            return R.ok();
        }else {
            return R.error();
        }
    }
    //修改
    @RequestMapping("/update")
    public R updatePreventRegionServiceById(PreventRegion preventRegion){
        Integer result = preventRegionService.updatePreventRegionServiceById(preventRegion);
        System.out.println(preventRegion);
        if (result ==1){
            return R.ok();
        }else {
            return R.error();
        }
    }
    //    部分删除
    @RequestMapping("/deleteAll")
    public R deleteAllPreventRegion(String str) {
        System.out.println("deleteAllPreventRegion str" + str);
        Integer i = preventRegionService.deleteAllPreventRegion(str);
        return i > 0 ? R.ok() : R.error();
    }
}
